﻿// <copyright file="TimesPeoplePage.xaml.cs" company="Microsoft Corporation">
// Copyright (c) 2009 Microsoft Corporation All Rights Reserved
// </copyright>
// <author>Michael S. Scherotter</author>
// <email>mischero@microsoft.com</email>
// <date>2009-05-07</date>
// <summary>TimesPeoplePage class definition</summary>

namespace DemoNYTimes
{
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media.Imaging;
    using NYTimes;

    /// <summary>
    /// Demo page for the TimesPeople API classes
    /// </summary>
    public partial class TimesPeoplePage : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the TimesPeoplePage class.
        /// </summary>
        public TimesPeoplePage()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Image failed event handler
        /// </summary>
        /// <param name="sender">the image that failed</param>
        /// <param name="e">the exception routed event arguments</param>
        private void OnImageFailed(object sender, ExceptionRoutedEventArgs e)
        {
            var image = sender as Image;

            BitmapImage bitmap = image.Source as BitmapImage;

            System.Diagnostics.Debug.WriteLine("Failed to display image: {0}", bitmap.UriSource);
        }

        /// <summary>
        /// Get the activity and profile data for a user
        /// </summary>
        /// <param name="sender">the button</param>
        /// <param name="e">the routed event arguments</param>
        private void OnGetData(object sender, RoutedEventArgs e)
        {
            var profile = this.Resources["TimesPeopleProfileDataSource"] as TimesPeopleProfile;

            profile.EmailAddress = this.EmailAddress.Text;

            var activities = this.Resources["TimesPeopleActivitiesDS"] as TimesPeopleActivities;

            activities.EmailAddress = this.EmailAddress.Text;
        }
    }
}
